package com.kingyun.gpsinspection.purificationservice.services.iam.innerservice.accessory.impl;

import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.DeviceVo;
import com.kingyun.gpsinspection.purificationservice.facade.service.iam.accessory.IamDeviceService;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.Device;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.OutDeviceService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangsy on 2017/2/23.
 */
public class IamDeviceServiceImpl implements IamDeviceService
{
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(IamDeviceServiceImpl.class);
    @Autowired(required = false)
    private OutDeviceService outDeviceService;

    @Override
    public Device selectByPrimaryKey(DeviceVo deviceVO) {
        Map<String, Object> map = this.getDeviceMap(deviceVO);

        if(map==null || map.size()==0) return null;

        List<Device> list  = (List<Device>)map.get("rows");
        if(list==null || list.size()==0) return  null;
        return list.get(0);
    }

    @Override
    public Map<String, Object> getDeviceMap(DeviceVo deviceVO) {
        Map<String, Object> map = new HashMap<>();
        try {
            map = outDeviceService.searchDevices(deviceVO);
        } catch (Exception e) {
            logger.info("调用设备接口，获取设备信息失败:" + e.getMessage());
        }
        return map;
    }
}
